//
// x-osk.h
//

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 */

#ifndef __KEYBOARD_H__
#define __KEYBOARD_H__

#include <gtkmm.h>
#include <iostream>
#include <fstream>
#include "xorglib.h"

#ifndef uchar
typedef unsigned char  uchar;
#endif
#ifndef uint
typedef unsigned int  uint;
#endif

using namespace std;

class XOSK
{
public:
    XOSK();
    virtual ~XOSK();
    
    Gtk::Window  *mp_window_kb;
    
protected:
    typedef struct
    {
        int   kb_x;
        int   kb_y;
        bool  dnd;
        
    } t_core_parms;
    
    void  set_keyboard_letters_to_case(bool lowercase);
    void  set_keyboard_non_letters_to_shift(bool up);
    bool  is_shift_down();
    bool  is_capslock_down();
    bool  is_ctrl_down();
    bool  is_alt_down();
    void  keysym_send(uint keysym);
    void  update_keyboard_labels();
    bool  config_file_load();
    void  config_file_save();
    
    bool  on_window_kb_button_release_event(GdkEventButton* event);
    bool  on_window_kb_motion_notify_event(GdkEventMotion* event);
    void  on_button_a_clicked();
    void  on_button_b_clicked();
    void  on_button_c_clicked();
    void  on_button_d_clicked();
    void  on_button_e_clicked();
    void  on_button_f_clicked();
    void  on_button_g_clicked();
    void  on_button_h_clicked();
    void  on_button_i_clicked();
    void  on_button_j_clicked();
    void  on_button_k_clicked();
    void  on_button_l_clicked();
    void  on_button_m_clicked();
    void  on_button_n_clicked();
    void  on_button_o_clicked();
    void  on_button_p_clicked();
    void  on_button_q_clicked();
    void  on_button_r_clicked();
    void  on_button_s_clicked();
    void  on_button_t_clicked();
    void  on_button_u_clicked();
    void  on_button_v_clicked();
    void  on_button_w_clicked();
    void  on_button_x_clicked();
    void  on_button_y_clicked();
    void  on_button_z_clicked();
    void  on_button_0_clicked();
    void  on_button_1_clicked();
    void  on_button_2_clicked();
    void  on_button_3_clicked();
    void  on_button_4_clicked();
    void  on_button_5_clicked();
    void  on_button_6_clicked();
    void  on_button_7_clicked();
    void  on_button_8_clicked();
    void  on_button_9_clicked();
    void  on_button_grave_clicked();
    void  on_button_minus_clicked();
    void  on_button_equal_clicked();
    void  on_button_bracketleft_clicked();
    void  on_button_bracketright_clicked();
    void  on_button_backslash_clicked();
    void  on_button_semicolon_clicked();
    void  on_button_apostrophe_clicked();
    void  on_button_comma_clicked();
    void  on_button_period_clicked();
    void  on_button_slash_clicked();
    void  on_button_tab_clicked();
    void  on_button_backspace_clicked();
    void  on_button_delete_clicked();
    void  on_button_return_clicked();
    void  on_button_home_clicked();
    void  on_button_end_clicked();
    void  on_button_space_clicked();
    void  on_button_left_clicked();
    void  on_button_right_clicked();
    void  on_button_up_clicked();
    void  on_button_down_clicked();
    void  on_button_quit_clicked();
    void  on_button_showhide_clicked();
    void  on_togglebutton_ctrl_toggled();
    void  on_togglebutton_alt_toggled();
    void  on_togglebutton_shift_toggled();
    void  on_togglebutton_capslock_toggled();
    
    XOrgLib                     m_xorg_lib;
    Glib::ustring               m_glade_dir_path;
    Glib::RefPtr<Gtk::Builder>  mr_builder;
    Gtk::Button                *mp_button_a;
    Gtk::Button                *mp_button_b;
    Gtk::Button                *mp_button_c;
    Gtk::Button                *mp_button_d;
    Gtk::Button                *mp_button_e;
    Gtk::Button                *mp_button_f;
    Gtk::Button                *mp_button_g;
    Gtk::Button                *mp_button_h;
    Gtk::Button                *mp_button_i;
    Gtk::Button                *mp_button_j;
    Gtk::Button                *mp_button_k;
    Gtk::Button                *mp_button_l;
    Gtk::Button                *mp_button_m;
    Gtk::Button                *mp_button_n;
    Gtk::Button                *mp_button_o;
    Gtk::Button                *mp_button_p;
    Gtk::Button                *mp_button_q;
    Gtk::Button                *mp_button_r;
    Gtk::Button                *mp_button_s;
    Gtk::Button                *mp_button_t;
    Gtk::Button                *mp_button_u;
    Gtk::Button                *mp_button_v;
    Gtk::Button                *mp_button_w;
    Gtk::Button                *mp_button_x;
    Gtk::Button                *mp_button_y;
    Gtk::Button                *mp_button_z;
    Gtk::Button                *mp_button_0;
    Gtk::Button                *mp_button_1;
    Gtk::Button                *mp_button_2;
    Gtk::Button                *mp_button_3;
    Gtk::Button                *mp_button_4;
    Gtk::Button                *mp_button_5;
    Gtk::Button                *mp_button_6;
    Gtk::Button                *mp_button_7;
    Gtk::Button                *mp_button_8;
    Gtk::Button                *mp_button_9;
    Gtk::Button                *mp_button_grave;
    Gtk::Button                *mp_button_minus;
    Gtk::Button                *mp_button_equal;
    Gtk::Button                *mp_button_bracketleft;
    Gtk::Button                *mp_button_bracketright;
    Gtk::Button                *mp_button_backslash;
    Gtk::Button                *mp_button_semicolon;
    Gtk::Button                *mp_button_apostrophe;
    Gtk::Button                *mp_button_comma;
    Gtk::Button                *mp_button_period;
    Gtk::Button                *mp_button_slash;
    Gtk::Button                *mp_button_tab;
    Gtk::Button                *mp_button_backspace;
    Gtk::Button                *mp_button_delete;
    Gtk::Button                *mp_button_return;
    Gtk::Button                *mp_button_home;
    Gtk::Button                *mp_button_end;
    Gtk::Button                *mp_button_space;
    Gtk::Button                *mp_button_left;
    Gtk::Button                *mp_button_right;
    Gtk::Button                *mp_button_up;
    Gtk::Button                *mp_button_down;
    Gtk::Button                *mp_button_quit, *mp_button_showhide;
    Gtk::ToggleButton          *mp_togglebutton_ctrl;
    Gtk::ToggleButton          *mp_togglebutton_alt;
    Gtk::ToggleButton          *mp_togglebutton_shift;
    Gtk::ToggleButton          *mp_togglebutton_capslock;
    Gtk::Box                   *mp_box_row_1, *mp_box_row_2, *mp_box_row_3;
    Gtk::Box                   *mp_box_row_4, *mp_box_row_5_showhide;
    bool                        m_moving;
    int                         m_initial_drag_x, m_initial_drag_y;
    int                         m_kb_x, m_kb_y, m_bsh_x, m_bsh_y;
    int                         m_kb_w, m_kb_h, m_bsh_w, m_bsh_h;
    Glib::ustring               m_config_dir, m_config_file;
    t_core_parms                m_core_parms;
};

#endif // __KEYBOARD_H__
